<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
                      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>Consuming an RSS Feed - Zend Framework Manual</title>

    <link href="../css/shCore.css" rel="stylesheet" type="text/css" />
    <link href="../css/shThemeDefault.css" rel="stylesheet" type="text/css" />
    <link href="../css/styles.css" media="all" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Zend Framework</h1>
<h2>Programmer's Reference Guide</h2>
<ul>
    <li><a href="../en/zend.feed.consuming-rss.html">Inglês (English)</a></li>
    <li><a href="../pt-br/zend.feed.consuming-rss.html">Português Brasileiro (Brazilian Portuguese)</a></li>
</ul>
<table width="100%">
    <tr valign="top">
        <td width="85%">
            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.feed.findFeeds.html">Retrieving Feeds from Web Pages</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.feed.html">Zend_Feed</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.feed.consuming-atom.html">Consuming an Atom Feed</a></div>
                    </td>
                </tr>
            </table>
<hr />
<div id="zend.feed.consuming-rss" class="section"><div class="info"><h1 class="title">Consuming an RSS Feed</h1></div>
    

    <p class="para">
        Reading an <acronym class="acronym">RSS</acronym> feed is as simple as instantiating a
        <span class="classname">Zend_Feed_Rss</span> object with the <acronym class="acronym">URL</acronym> of the feed:
    </p>

    <pre class="programlisting brush: php">
$channel = new Zend_Feed_Rss(&#039;http://rss.example.com/channelName&#039;);
</pre>


    <p class="para">
        If any errors occur fetching the feed, a <span class="classname">Zend_Feed_Exception</span> will be
        thrown.
    </p>

    <p class="para">
        Once you have a feed object, you can access any of the standard <acronym class="acronym">RSS</acronym>
        &quot;channel&quot; properties directly on the object:
    </p>

    <pre class="programlisting brush: php">
echo $channel-&gt;title();
</pre>


    <p class="para">
        Note the function syntax. <span class="classname">Zend_Feed</span> uses a convention of treating
        properties as <acronym class="acronym">XML</acronym> object if they are requested with variable &quot;getter&quot;
        syntax (<strong class="command">$obj-&gt;property</strong>) and as strings if they are access with method
        syntax (<strong class="command">$obj-&gt;property()</strong>). This enables access to the full text of any
        individual node while still allowing full access to all children.
    </p>

    <p class="para">
        If channel properties have attributes, they are accessible using <acronym class="acronym">PHP</acronym>&#039;s
        array syntax:
    </p>

    <pre class="programlisting brush: php">
echo $channel-&gt;category[&#039;domain&#039;];
</pre>


    <p class="para">
        Since <acronym class="acronym">XML</acronym> attributes cannot have children, method syntax is not necessary
        for accessing attribute values.
    </p>

    <p class="para">
        Most commonly you&#039;ll want to loop through the feed and do something with its entries.
        <span class="classname">Zend_Feed_Abstract</span> implements <acronym class="acronym">PHP</acronym>&#039;s
        <span class="classname">Iterator</span> interface, so printing all titles of articles in a channel
        is just a matter of:
    </p>

    <pre class="programlisting brush: php">
foreach ($channel as $item) {
    echo $item-&gt;title() . &quot;\n&quot;;
}
</pre>


    <p class="para">
        If you are not familiar with <acronym class="acronym">RSS</acronym>, here are the standard elements you can
        expect to be available in an <acronym class="acronym">RSS</acronym> channel and in individual
        <acronym class="acronym">RSS</acronym> items (entries).
    </p>

    <p class="para">
        Required channel elements:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para"><span class="property">title</span> - The name of the channel</p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="property">link</span> - The <acronym class="acronym">URL</acronym> of the web site
                corresponding to the channel
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="property">description</span> - A sentence or several describing the channel
            </p>
        </li>
    </ul>

    <p class="para">
        Common optional channel elements:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para">
                <span class="property">pubDate</span> - The publication date of this set of content, in
                <acronym class="acronym">RFC</acronym> 822 date format
            </p>
        </li>

        <li class="listitem">
            <p class="para"><span class="property">language</span> - The language the channel is written in</p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="property">category</span> - One or more (specified by multiple tags)
                categories the channel belongs to
            </p>
        </li>
    </ul>

    <p class="para">
        <acronym class="acronym">RSS</acronym> <em class="emphasis">&lt;item&gt;</em> elements do not have any strictly
        required elements. However, either <span class="property">title</span> or
        <span class="property">description</span> must be present.
    </p>

    <p class="para">
        Common item elements:
    </p>

    <ul class="itemizedlist">
        <li class="listitem">
            <p class="para"><span class="property">title</span> - The title of the item</p>
        </li>

        <li class="listitem">
            <p class="para"><span class="property">link</span> - The <acronym class="acronym">URL</acronym> of the item</p>
        </li>

        <li class="listitem">
            <p class="para"><span class="property">description</span> - A synopsis of the item</p>
        </li>

        <li class="listitem">
            <p class="para"><span class="property">author</span> - The author&#039;s email address</p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="property">category</span> - One more categories that the item belongs to
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="property">comments</span> - <acronym class="acronym">URL</acronym> of comments relating to
                this item
            </p>
        </li>

        <li class="listitem">
            <p class="para">
                <span class="property">pubDate</span> - The date the item was published, in
                <acronym class="acronym">RFC</acronym> 822 date format
            </p>
        </li>
    </ul>

    <p class="para">
        In your code you can always test to see if an element is non-empty with:
    </p>

    <pre class="programlisting brush: php">
if ($item-&gt;propname()) {
    // ... proceed.
}
</pre>


    <p class="para">
        If you use <strong class="command">$item-&gt;propname</strong> instead, you will always get an empty object
        which will evaluate to <b><tt>TRUE</tt></b>, so your check will fail.
    </p>

    <p class="para">
        For further information, the official <acronym class="acronym">RSS</acronym> 2.0 specification is available
        at: <a href="http://blogs.law.harvard.edu/tech/rss" class="link external">&raquo; http://blogs.law.harvard.edu/tech/rss</a>
    </p>
</div>
        <hr />

            <table width="100%">
                <tr>
                    <td width="25%" style="text-align: left;">
                    <a href="zend.feed.findFeeds.html">Retrieving Feeds from Web Pages</a>
                    </td>

                    <td width="50%" style="text-align: center;">
                        <div class="up"><span class="up"><a href="zend.feed.html">Zend_Feed</a></span><br />
                        <span class="home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></span></div>
                    </td>

                    <td width="25%" style="text-align: right;">
                        <div class="next" style="text-align: right; float: right;"><a href="zend.feed.consuming-atom.html">Consuming an Atom Feed</a></div>
                    </td>
                </tr>
            </table>
</td>
        <td style="font-size: smaller;" width="15%"> <style type="text/css">
#leftbar {
	float: left;
	width: 186px;
	padding: 5px;
	font-size: smaller;
}
ul.toc {
	margin: 0px 5px 5px 5px;
	padding: 0px;
}
ul.toc li {
	font-size: 85%;
	margin: 1px 0 1px 1px;
	padding: 1px 0 1px 11px;
	list-style-type: none;
	background-repeat: no-repeat;
	background-position: center left;
}
ul.toc li.header {
	font-size: 115%;
	padding: 5px 0px 5px 11px;
	border-bottom: 1px solid #cccccc;
	margin-bottom: 5px;
}
ul.toc li.active {
	font-weight: bold;
}
ul.toc li a {
	text-decoration: none;
}
ul.toc li a:hover {
	text-decoration: underline;
}
</style>
 <ul class="toc">
  <li class="header home"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="manual.html">Guia de Refer&ecirc;ncia do Programador</a></li>
  <li class="header up"><a href="reference.html">Refer&ecirc;ncia do Zend Framework</a></li>
  <li class="header up"><a href="zend.feed.html">Zend_Feed</a></li>
  <li><a href="zend.feed.introduction.html">Introduction</a></li>
  <li><a href="zend.feed.importing.html">Importing Feeds</a></li>
  <li><a href="zend.feed.findFeeds.html">Retrieving Feeds from Web Pages</a></li>
  <li class="active"><a href="zend.feed.consuming-rss.html">Consuming an RSS Feed</a></li>
  <li><a href="zend.feed.consuming-atom.html">Consuming an Atom Feed</a></li>
  <li><a href="zend.feed.consuming-atom-single-entry.html">Consuming a Single Atom Entry</a></li>
  <li><a href="zend.feed.modifying-feed.html">Modifying Feed and Entry structures</a></li>
  <li><a href="zend.feed.custom-feed.html">Custom Feed and Entry Classes</a></li>
  <li><a href="zend.feed.reader.html">Zend_Feed_Reader</a></li>
  <li><a href="zend.feed.writer.html">Zend_Feed_Writer</a></li>
  <li><a href="zend.feed.pubsubhubbub.introduction.html">Zend_Feed_Pubsubhubbub</a></li>
 </ul>
 </td>
    </tr>
</table>

<script type="text/javascript" src="../js/shCore.js"></script>
<script type="text/javascript" src="../js/shAutoloader.js"></script>
<script type="text/javascript" src="../js/main.js"></script>

</body>
</html>